package com.eastedu.superise.handler.question.handler.completion;

import java.util.Objects;
import java.util.function.BiPredicate;

/**
 * The enum Match type.
 *
 * @author luozhenzhong
 */
public enum MatchType {
    /**
     * The Strict.
     */
    STRICT("严格模式", (stem, answer) -> {
        // 题干和答案无序且空格数量一致, 同时答案必须只有一行或者空格数量等于段落数量
        boolean spaceCountEqualParagraphCount = answer.getParagraphCount() == 1 || answer.getParagraphCount() == answer.getSpaceCount();

        boolean disordered = stem.isDisordered() && answer.isDisordered()
                && stem.getSpaceCount() == answer.getSpaceCount()
                && spaceCountEqualParagraphCount;

        boolean ordered = !stem.isDisordered() && !answer.isDisordered()
                && stem.isBeginFrom1() && answer.isBeginFrom1()
                && stem.isContinuous() && answer.isContinuous()
                && stem.getOrderCount() == answer.getOrderCount()
                && stem.getSpaceCount() == answer.getSpaceCount();
        return disordered || ordered;
    }),
    /**
     * The Ignore answer order.
     */
    IGNORE_ANSWER_ORDER("忽略答案序号", (stem, answer) -> {
        if (answer == null) {
            return stem.isDisordered() ||
                    (!stem.isDisordered() && stem.isBeginFrom1() && stem.isContinuous());
        }

        boolean spaceCountMatches = stem.getSpaceCount() == answer.getSpaceCount();
        if (!spaceCountMatches) {
            return false;
        }

        return stem.isDisordered() ||
                (!stem.isDisordered() && stem.isBeginFrom1() && stem.isContinuous());
    }),
    ;

    private final String name;
    private final BiPredicate<ContentSummary, ContentSummary> predicate;

    MatchType(String name, BiPredicate<ContentSummary, ContentSummary> predicate) {
        this.name = name;
        this.predicate = predicate;
    }

    /**
     * Gets name.
     *
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * Gets predicate.
     *
     * @return the predicate
     */
    public BiPredicate<ContentSummary, ContentSummary> getPredicate() {
        return predicate;
    }
}
